Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Improve exists check in JpaQueryExecution #3715

Closed
wants to merge 1 commit into from

Conversation

minwoo1999
Copy link
Contributor

@minwoo1999 minwoo1999 commented Dec 13, 2024

Changes

Updated getResultList().isEmpty() to getResultStream().findFirst().isPresent() for checking query existence.
Improved performance by processing only the first result.

Reason

It seems that this method is only meant to check if the query exists. Therefore, fetching the entire query result does not seem necessary.
Avoids loading all results into memory, reducing overhead and improving efficiency.

Testing

Verified with existing test cases, ensuring identical results.

Review Request

Please review and share any feedback. 🙇‍♂️

by using getResultStream and findFirst
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Dec 13, 2024
@mp911de
Copy link
Member

mp911de commented Dec 16, 2024

ExistsExecution is only used for derived queries where we set query.setMaxResults(1). Therefore, instantiating a Java 8 stream instead of reading one result into a List is almost the same overhead. We want to keep our code as-is.

@mp911de mp911de closed this Dec 16, 2024
@mp911de mp911de added status: declined A suggestion or change that we don't feel we should currently apply and removed status: waiting-for-triage An issue we've not yet triaged labels Dec 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: declined A suggestion or change that we don't feel we should currently apply
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants